#!/usr/bin/env python
 
import telnetlib
import threading
 
def get_ip_status(ip,port):
    server = telnetlib.Telnet()
    try:
        server.open(ip,port)
        print('{0} port {1} is open'.format(ip, port))
    except Exception as err:
        #print('{0} port {1} is not open'.format(ip, port))
        ()
    finally:
        server.close()
   

if __name__ == '__main__':
    host = '106.15.227.81'
    threads = []
    threadSize=0
    for port in range(20,10000):
        threadSize=threadSize+1
        t = threading.Thread(target=get_ip_status,args=(host,port))
        t.start()
        threads.append(t)
        if threadSize>1000:
            for t in threads:
                t.join()
            threadSize=0
            threads=[]
 
    for t in threads:
        t.join()